(function () {

    function register() {
        let name = document.getElementById("reUsername").value;
        let pwd = document.getElementById("rePassword").value;
        let pwdAgain = document.getElementById("rePasswordAgain").value;

        if ((name == null || name == "") || (pwd == null || pwd == "")) {
            alert("用户名或密码不能为空！！");
        } else if (pwd !== pwdAgain) {
            alert("两次输入的密码不一致");
        } else {
            let parms = {
                username: name,
                password: pwd
            }
            fetch("http://gtgt.vip:3333/user/register", {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(parms)
            }).then(res => res.json())
                .then(data => {
                    console.log("===data====", data)
                    if (data && data.code === 200) {
                        window.location.href = "./index.html";
                    } else {
                        alert(data.msg)
                    }
                })
        }
    }

    document.getElementById('sureRegBtn').addEventListener("click", register, false)

}())